import { ref } from 'vue';

/**
 * @description 管理 ref 状态，TRUE or FALSE
 * @author wfd
 * @date 2022/11/14 20:15
 * @example
 * @param {boolean} defaultValue
 * @returns {readonly [Ref<UnwrapRef<boolean>>, ((value?: boolean) => void)]}
 */
export function useBoolean (defaultValue = false) {
  const state = ref(defaultValue);
  const toggle = (value = !state.value) => {
    state.value = value;
  };
  
  return [state, toggle] as const;
}
